[Dataflow Streaming] Prepare BoundedQueueExecutor for MultiKey bundles#38592
[Dataflow Streaming] Prepare BoundedQueueExecutor for MultiKey bundles#38592arunpandianp wants to merge 4 commits into
Conversation
|
R: @scwhittle |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request prepares the BoundedQueueExecutor for multi-key bundles by updating the work execution lifecycle. By introducing a WorkResult object, the system can now accurately track and decrement resource budgets (items and bytes) after work execution. The changes include refactoring existing interfaces to support this return type, improving error handling via a new utility class, and ensuring that resource budgets are correctly reclaimed even in the event of task submission failures. Highlights
New Features🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
|
Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment |
There was a problem hiding this comment.
Code Review
This pull request refactors the streaming worker's execution logic by introducing a WorkResult class to track processed items and bytes. ExecutableWork is updated to return this result, and BoundedQueueExecutor is modified to manage resource budgets using WorkResult instead of raw byte counts. Additionally, an ExceptionUtils utility is added for standardized exception propagation. A critical review comment identifies a potential resource leak in BoundedQueueExecutor where the executeMonitorHeld method for ExecutableWork lacks error handling for task submission and execution failures, which could lead to permanent capacity leaks in the JVM if not addressed.
| executor.execute( | ||
| () -> { | ||
| // Any execution exception thrown by work.run() propagates uncaught, triggering | ||
| // the default JVM UncaughtExceptionHandler which immediately crashes/terminates | ||
| // the JVM. Since the process exits immediately, reclaiming resource budgets in | ||
| // this JVM is unnecessary. Furthermore, since a failed execution does not return | ||
| // a WorkResult, we do not have a good/accurate fallback value to decrement. | ||
| WorkResult result = work.run(); | ||
| decrementCounters(result); | ||
| }); |
There was a problem hiding this comment.
The executeMonitorHeld method for ExecutableWork lacks error handling for task submission and execution failures, which can lead to resource leaks in elementsOutstanding and bytesOutstanding.
- If
executor.execute()throws aRejectedExecutionException(e.g., during worker shutdown), the counters incremented just before will never be decremented, leading to a permanent capacity leak in the JVM. - If
work.run()throws an exception and the JVM does not immediately terminate (e.g., if the exception is caught by the thread pool's uncaught exception handler but the process continues), the counters will also leak.
This implementation should be made consistent with the Runnable version of executeMonitorHeld (lines 248-272), which correctly handles these scenarios. Even if a JVM crash is expected on work failure, providing a defensive decrement (using the initial workBytes as a fallback) is safer.
try {
executor.execute(
() -> {
WorkResult result = null;
try {
result = work.run();
} finally {
// Any execution exception thrown by work.run() propagates uncaught, triggering
// the default JVM UncaughtExceptionHandler which immediately crashes/terminates
// the JVM. Since the process exits immediately, reclaiming resource budgets in
// this JVM is unnecessary. Furthermore, since a failed execution does not return
// a WorkResult, we fallback to decrementing the initial budget to prevent
// resource leaks in case the JVM does not crash.
decrementCounters(result != null ? result : WorkResult.create(1, workBytes));
}
});
} catch (Throwable e) {
// If the execute() call threw an exception, decrement counters here.
decrementCounters(WorkResult.create(1, workBytes));
throw ExceptionUtils.propagate(e);
}|
Changing a few things, not ready for review. |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism for inline work execution within the BoundedQueueExecutor by utilizing a new BoundedQueueExecutorWorkHandle interface. Key changes include refactoring ExecutableWork to support this handle, adding a pollWork method to BoundedQueueExecutor for retrieving queued tasks, and implementing a Budget tracking system to manage outstanding elements and bytes during batch processing. Feedback was provided to ensure the close() method in the handle implementation is idempotent to comply with the AutoCloseable contract and to implement safer type checking when casting the handle in the pollWork method.
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism for polling and executing work inline within the BoundedQueueExecutor by implementing a new BoundedQueueExecutorWorkHandle interface. Key changes include refactoring ExecutableWork to support these handles and updating the executor to track outstanding work using a Budget object that accounts for both element counts and byte sizes. Feedback suggests making the close() method in the handle implementation idempotent to avoid masking exceptions and adding a type check in pollWork to prevent potential ClassCastException when casting the handle.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to poll and execute work items inline within the BoundedQueueExecutor, facilitating better control over work budget and resource management. Key changes include the introduction of BoundedQueueExecutorWorkHandle and ExecutableWork to track work budgets, and the addition of a pollWork method to allow worker threads to pull additional tasks from the queue. Feedback was provided regarding the pollWork method's behavior of executing non-QueuedWork items on the calling thread, which could potentially impact latency if those tasks are long-running.
| while (true) { | ||
| Runnable runnable = executor.getQueue().poll(); | ||
| if (runnable == null) { | ||
| return Optional.empty(); | ||
| } | ||
| if (runnable instanceof QueuedWork) { | ||
| QueuedWork queuedWork = (QueuedWork) runnable; | ||
| queuedWork.cancelHandle(); | ||
| internalHandle.addBudget(1, queuedWork.getWorkBytes()); | ||
| return Optional.of(queuedWork.getWork()); | ||
| } | ||
| // Pop and execute standard callbacks immediately on the calling thread to drain the queue | ||
| runnable.run(); | ||
| } |
There was a problem hiding this comment.
The pollWork method executes any non-QueuedWork items (such as callbacks submitted via forceExecute(Runnable)) directly on the calling thread to "drain the queue" while searching for the next QueuedWork. This is a significant change in behavior, as these tasks were previously always executed by the executor's thread pool. If these callbacks are long-running or perform blocking operations, they could delay the completion of the current work item and the release of its associated budget. While this is necessary to reach items further back in the LinkedBlockingQueue, it should be monitored for potential impact on worker thread latency.
There was a problem hiding this comment.
The getter is unused now. Planning to improve the logic before using it. This change is just setting up the Handles and getters.
Adds a getter that will be used by StreamingWorkScheduler/Context to pull more work from the queue when executing a multi key bundle. The queuing logic will be be improved and getter signature will change in a later PR.